﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace IGS.Core.Systems
{
    public class NBodySystem : INBodySystem
    {
        private readonly IInteractable[] Bodies;

        public NBodySystem(IInteractable[] bodies)
        {
            Bodies = bodies;
        }

        public int Length
        {
            get { return Bodies.Length;  }
        }

        public double KineticEnergy
        {
            get { return Bodies.Sum(b => b.KineticEnergy); }
        }

        public double PotentialEnergy
        {
            get { return 0.5 * Bodies.Sum(b => b.PotentialEnergy); }
        }

        public IInteractable this[int i]
        {
            get { return Bodies[i]; }
        }

        public IEnumerator<IInteractable> GetEnumerator()
        {
            return Bodies.AsEnumerable().GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}